﻿using System;
using System.Collections.Generic;
using System.Drawing;

namespace Fiche_Personnes
{
    class Personne : IComparable
    {
        public Personne(string nom, string prenom)
        {
            this.m_Nom = nom; this.m_Prenom = prenom;
            this.m_Naissance = new DateTime(0);

            this.m_Parcours = new Dictionary<int, Institution>();
            this.m_Notes = new List<Note>();
        }
        public Personne(string nom, string prenom, DateTime dateNaissance, string photo)
        {
            this.m_Nom = nom; this.m_Prenom = prenom;
            this.m_Naissance = dateNaissance;

            this.m_Parcours = new Dictionary<int, Institution>();
            this.m_Notes = new List<Note>();

            this.m_Photo = new Bitmap(photo);
            this.m_Photo = new Bitmap(this.m_Photo, new Size(70, 100));
        }
        public Personne(string nom, string prenom, string photo)
        {
            this.m_Nom = nom;this.m_Prenom = prenom;
            this.m_Naissance = new DateTime(-1);
            this.m_Parcours = new Dictionary<int, Institution>();
            this.m_Notes = new List<Note>();
            this.m_Photo = new Bitmap(photo);
            this.m_Photo = new Bitmap(this.m_Photo, new Size(70, 100));
        }

        public void changePhoto(string photo)
        {
            this.m_Photo = new Bitmap(photo);
            this.m_Photo = new Bitmap(this.m_Photo, new Size(70, 100));
        }
        public void addInstitution(Institution institution, int annee)
        { this.m_Parcours.Add(annee, institution); }
        public void addNote(string note, params string[] tags)
        { this.m_Notes.Add(new Note(note, tags)); }
        #region Ajout Parents
        public void addPere(Personne p) { this.m_Pere = p; }
        public void addMere(Personne m) { this.m_Mere = m; }
        public void addParents(Personne pere, Personne mere) { this.addMere(mere); this.addPere(pere); }
        #endregion

        private string m_Nom; private string m_Prenom;
            public string Nom { get { return this.m_Nom.ToUpper() + " " + this.m_Prenom; } }
        private DateTime m_Naissance;
            public int Age 
            { get { return (this.m_Naissance.Ticks == -1 ? -1 : (int)((new TimeSpan(DateTime.Now.Ticks - m_Naissance.Ticks)).TotalDays)); } }
        private System.Drawing.Bitmap m_Photo;

        private Personne m_Pere, m_Mere;
            public Personne Pere { get { return this.m_Pere; } }
            public Personne Mere { get { return this.m_Mere; } }

        private Dictionary<int, Institution> m_Parcours; // L'année associée est l'année x - x+1 (ex : 2010 => 2010-2011)

        private List<Note> m_Notes;
            public List<string> Notes { get { List<string> retour = new List<string>(); foreach(Note n in this.m_Notes) retour.Add(n.Annotation); return retour; } }
        

        public int CompareTo(object o)
        { 
            Personne p = o as Personne;
            if(p == null) throw new Exception("Object is not a Personne");
            return this.CompareTo(p.Nom);

        }
    }
}
